<?php

	class LoginView{
		
		private $user = "user";
		private $password = "pass";
		private $login = "login";
		private $logout = "logout";
		private $rememberMe = "rememberMe";
				
		//Metoder
		public function CreateLoginBox()
		{				
			$loginForm = "<div id='login'>
							<form action='' method='post'>
								<fieldset>
										<label for='user'>Användarnamn</label>
										<input type='text' id='user' name='$this->user' />
										<br />
										<label for='pass'>Lösenord</label>
										<input type='password' id='pass' name='$this->password' />
										<br />
										<input type='checkbox' value='$this->rememberMe' name='$this->rememberMe' id='remember' />
										<label for='remember'>Kom ihåg mig</label>
										<input type='submit' id='submitButton' name='$this->login' value='Login' />
								</fieldset>
							</form>
						</div>\n";
			
			return $loginForm;
		}
		
		public function CreateLogoutBox()
		{
			return " <div id='logut'>
						<form action='' method='post' >
							<input type='submit' id='logutButton' name='$this->logout' value='Logga ut' />
						</form>
					</div>\n";
		}
		
		public function CreateLogoutStatusBox()
		{			
			return "<div id='status' class='green'>
						<p>Du har nu loggats ut.</p>
					</div>";
		}
		
		public function CreateFailLoginStatusBox()
		{			
			return "<div id='status' class='red'>
						<p>Felaktiga användaruppgifter, var vänlig försök igen.</p>
					</div>";
		}
		
		public function CreateSuccessLoginStatusBox($username)
		{
			return "<div id='status' class='green'>
						<p>Grattis $username, du har nu loggats in.</p>
					</div>";
		}
		
		public function GetUserName()
		{
			if(isset($_COOKIE[$this->user])){
				return $_COOKIE[$this->user];
			}
			if (isset($_POST[$this->user]) == true) {
	      		return $_POST[$this->user];
	    	}
	    	return NULL;
		}
		
		public function GetPassword()
		{
			if(isset($_COOKIE[$this->password])){
				return $_COOKIE[$this->password];
			}
			if (isset($_POST[$this->password]) == true) {
	      		return $_POST[$this->password];
			}
			return NULL;
		}
		
		public function CreateCookie($user, $pass)
		{
			setcookie($this->user, $user, time()+60*60*24*30);
			setcookie($this->password, $pass, time()+60*60*24*30);
		}
		
		public function DestroyCookie()
		{
			setcookie($this->user, "", time() -3600);
			setcookie($this->password, "", time() -3600);
		}
		
		public function GetCheckBoxValue()
		{
			if(isset($_POST[$this->rememberMe])){
				return true;
			}
			return false;
		}
		
		public function TriedToLogin()
		{
			if(isset($_COOKIE[$this->user])){
				return true;
			}
			if(isset($_POST[$this->login])){
				return true;
			}
			return false;
		}
		
		public function TriedToLogOut()
		{
			if(isset($_POST[$this->logout])){
				return true;
			}
			return false;
		}
	}
?>

